package com.ctshk.sapp.custom.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;

import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.custom.dto.trip.*;
import com.ctshk.rpc.custom.req.trip.*;
import com.ctshk.rpc.custom.service.ICustomizedTripScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 团期管理
 * </p>
 *
 * @author 叶冠峰
 * @since 1/20/2021
 */
@Api(value="团期管理", tags="团期管理")
@RestController
@Slf4j
@RequestMapping("/trip-schedule")
public class CustomizedTripScheduleController extends BaseController {

    @DubboReference
    private ICustomizedTripScheduleService tripScheduleService;

    @ApiOperation(value="团期列表(产品中心)", notes="团期列表(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期列表", operDesc = "团期列表")
    @PostMapping("/list")
    public Result<PageResponse<TripScheduleListDTO>> tripScheduleList(@RequestBody @Valid TripScheduleListReq tripScheduleListReq) {
        try{
            TokenUser currentUser = getCurrentUser(getRequest());
            PageResponse<TripScheduleListDTO> list = tripScheduleService.list(tripScheduleListReq, currentUser);
            return Result.success(list);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期列表(预订中心)", notes="团期列表(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期列表", operDesc = "团期列表")
    @PostMapping("/customized-center-list")
    public Result<PageResponse<TripScheduleListDTO>> customizedCenterList(@RequestBody @Valid TripScheduleCustomizedCenterListReq tripScheduleCustomizedCenterListReq) {
        try{
            TokenUser currentUser = getCurrentUser(getRequest());
            PageResponse<TripScheduleListDTO> list = tripScheduleService.customizedCenterList(tripScheduleCustomizedCenterListReq, currentUser);
            return Result.success(list);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value="团期基本信息", notes="团期基本信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期基本信息", operDesc = "团期基本信息")
    @PostMapping("/base-info")
    public Result<TripScheduleBaseInfoDTO> tripScheduleBaseInfo(@RequestBody @Valid TripScheduleInfoReq tripScheduleInfoReq) {
        try{
            return tripScheduleService.tripScheduleBaseInfo(tripScheduleInfoReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="保存团期基本信息", notes="保存团期基本信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.ADD, operTitle = "保存团期基本信息", operDesc = "保存团期基本信息")
    @PostMapping("/save-base-info")
    public Result saveTripScheduleBaseInfo(@RequestBody @Valid SaveTripScheduleBaseInfoReq saveTripScheduleBaseInfoReq) {
        try{
            TokenUser user = getCurrentUser(getRequest());
            return tripScheduleService.saveTripScheduleBaseInfo(saveTripScheduleBaseInfoReq,user);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value="根据团期id获取销售设置", notes="根据团期id团期销售设置信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "根据团期id团期销售设置信息", operDesc = "根据团期id团期销售设置信息")
    @PostMapping("/sales-setting-info")
    public Result<TripScheduleSalesSettingInfoDTO> salesSettingInfo(@RequestBody @Valid TripScheduleIdReq tripScheduleIdReq) {
        try{
            return tripScheduleService.salesSettingInfo(tripScheduleIdReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="根据报价单获取销售设置", notes="根据报价单获取团期销售设置信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "根据报价单获取团期销售设置信息", operDesc = "根据报价单获取团期销售设置信息")
    @PostMapping("/sales-setting-info-by-quotation")
    public Result<SalesSettingPackageInfoDTO> salesSettingInfoByQuotation(@RequestBody @Valid TripScheduleSalesSettingInfoReq tripScheduleSalesSettingInfoReq) {
        try{
            return tripScheduleService.salesSettingInfoByQuotation(tripScheduleSalesSettingInfoReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="保存团期销售设置", notes="保存团期销售设置(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.ADD, operTitle = "保存团期销售设置", operDesc = "保存团期销售设置")
    @PostMapping("/save-sales-setting")
    public Result saveTripScheduleSalesSetting(@RequestBody @Valid SaveTripScheduleSalesSettingReq saveTripScheduleSalesSettingReq) {
        try{
            TokenUser user = getCurrentUser(getRequest());
            return tripScheduleService.saveTripScheduleSalesSetting(saveTripScheduleSalesSettingReq,user);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期行程信息", notes="团期行程信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期行程信息", operDesc = "团期行程信息")
    @PostMapping("/trip-info")
    public Result<TripScheduleItineraryDTO> tripInfo(@RequestBody @Valid TripScheduleIdReq tripScheduleIdReq) {
        try{
            return tripScheduleService.tripInfo(tripScheduleIdReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="保存团期行程信息", notes="保存团期行程信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.ADD, operTitle = "保存团期行程信息", operDesc = "保存团期行程信息")
    @PostMapping("/save-itinerary-info")
    public Result saveItineraryInfo(@RequestBody @Valid SeriesTripScheduleItineraryDayReq seriesTripScheduleItineraryDayReq) {
        try{
            TokenUser user = getCurrentUser(getRequest());
            return tripScheduleService.saveItineraryInfo(seriesTripScheduleItineraryDayReq,user);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期详情-基本内容", notes="团期详情-基本内容(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期详情-基本内容", operDesc = "团期详情-基本内容")
    @PostMapping("/detail-base")
    public Result<TripScheduleBaseInfoDTO> detailBase(@RequestBody @Valid TripScheduleDetailInfoReq tripScheduleDetailInfoReq) {
        try{
            TokenUser user = getCurrentUser(getRequest());
            return tripScheduleService.detailBase(tripScheduleDetailInfoReq,user.getId());
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期详情-行程安排", notes="团期详情-行程安排(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期详情-行程安排", operDesc = "团期详情-行程安排")
    @PostMapping("/detail-trip")
    public Result<TripScheduleItineraryDTO> detailTrip(@RequestBody @Valid TripScheduleDetailInfoReq tripScheduleDetailInfoReq) {
        try{
            return tripScheduleService.detailTrip(tripScheduleDetailInfoReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期详情-檔案總管理", notes="团期详情-檔案總管理(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期详情-檔案總管理", operDesc = "团期详情-檔案總管理")
    @PostMapping("/detail-archives")
    public Result<List<ArchivesJson>> detailArchives(@RequestBody @Valid TripScheduleDetailInfoReq tripScheduleDetailInfoReq) {
        try{
            return tripScheduleService.detailArchives(tripScheduleDetailInfoReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="定制包团下单信息", notes="定制包团下单信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "定制包团下单信息", operDesc = "定制包团下单信息")
    @PostMapping("/create-order-info")
    public Result<ScheduleOrderPageInfoDTO> createOrderInfo(@RequestBody @Valid TripScheduleDetailInfoReq tripScheduleDetailInfoReq) {
        try{
            return tripScheduleService.createOrderInfo(tripScheduleDetailInfoReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="操作订单-调整项目列表", notes="操作订单-调整项目列表(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "操作订单-调整项目列表", operDesc = "操作订单-调整项目列表")
    @PostMapping("/adjust-project-list")
    public Result<TripScheduleAdjustProjectDTO> adjustProjectList(@RequestBody @Valid TripScheduleAdjustProjectListReq req) {
        try{
            return tripScheduleService.adjustProjectList(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期操作", notes="团期操作(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.UPDATE, operTitle = "团期操作", operDesc = "团期操作")
    @PostMapping("/operate-trip")
    public Result operateTrip(@RequestBody @Valid TripScheduleOperateReq req) {
        try{
            return tripScheduleService.operateTrip(req,getCurrentUser(getRequest()));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="定制包团列表(其他模块调用)", notes="定制包团列表(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "定制包团列表(其他模块调用)", operDesc = "定制包团列表(其他模块调用)")
    @PostMapping("/schedule-list")
    public Result<PageResponse<TripScheduleDTO>> scheduleList(@RequestBody ScheduleListReq req) {
        try{
            PageResponse<TripScheduleDTO> list = tripScheduleService.scheduleList(req);
            return Result.success(list);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="完团审批", notes="完团审批(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.UPDATE, operTitle = "完团审批", operDesc = "完团审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid TripScheduleApprovalReq req) {
        try{
            req.setUserId(getCurrentUser(getRequest()).getId());
            return tripScheduleService.approval(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="旅客名单-团期信息", notes="旅客名单-团期信息(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.UPDATE, operTitle = "旅客名单-团期信息", operDesc = "旅客名单-团期信息")
    @GetMapping("/tourist-schedule-info/{scheduleId}")
    public Result<TouristScheduleInfoDTO> touristScheduleInfo(@PathVariable Long scheduleId) {
        try{
            return tripScheduleService.touristScheduleInfo(scheduleId);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期操作-茶会通知", notes="团期操作-茶会通知(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.UPDATE, operTitle = "团期操作-茶会通知", operDesc = "团期操作-茶会通知")
    @PostMapping("/tea-party-notice")
    public Result teaPartyNotice(@RequestBody @Valid TripScheduleTeaPartyNoticeReq req) {
        try{
            return tripScheduleService.teaPartyNotice(req,getCurrentUser(getRequest()));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期操作-财务锁定状态修改", notes="团期操作-财务锁定状态修改(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.CUSTOM, operType = OperationLogType.QUERY, operTitle = "团期操作-财务锁定状态修改", operDesc = "团期操作-财务锁定状态修改")
    @PostMapping("/lock-status")
    public Result lockStatus(@RequestBody @Valid TripScheduleAdjustProjectListReq req) {
        try{
            return tripScheduleService.lockStatus(req,getCurrentUser(getRequest()).getId());
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

}

